package com.lo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lo.common.JsonResult;
import com.lo.dao.CommentMapper;
import com.lo.dao.TeacherMapper;
import com.lo.dao.UserMapper;
import com.lo.entity.CourseWithTCHName;
import com.lo.entity.Message;
import com.lo.entity.Teacher;
import com.lo.entity.User;
import com.lo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private CommentMapper commentMapper;
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

//    @Override
//    public JsonResult login(String username, String password) {
//        List<Teacher> teachers = teacherMapper.selectByUsernameAndPassword(username,password);
//        if (teachers.size()>1){
//            throw new RuntimeException("用户名重复，查询多个用户，请联系管理员");
//        }
//        if (teachers.size()<=0){
//            return new JsonResult(3,"用户名或密码错误",null);
//        }
//        if (teachers.get(0).getIsBanned()==1){
//            return new JsonResult(3,"该用户已被封禁，请联系管理员解封",null);
//        }
//        JsonResult result =  new JsonResult(0,"教师登录成功",teachers.get(0));
//        return result;
//    }


//    @Override
//    public PageInfo page(int pageNum, int pageSize, Long id, String search) {
//        PageHelper.startPage(pageNum,pageSize);
//        List<Teacher> teachers = teacherMapper.selectByTidAndExamined(id,search);
//        System.out.println(teachers);
//        PageInfo pageInfo = new PageInfo(teachers);
//        return pageInfo;
//    }

//    @Override
//    public PageInfo NotExamineCoursePage(int pageNum, int pageSize, Long id, String search) {
//        PageHelper.startPage(pageNum,pageSize);
//        List<Teacher> teachers = teacherMapper.selectByTidAndNotExamine(id,search);
//        PageInfo pageInfo = new PageInfo(teachers);
//        return pageInfo;
//    }

//    @Override
//    public JsonResult selectTeacherMessage(Long id) {
//        List<Teacher> teachers = teacherMapper.selectById(id);
//        if (teachers.size()<=0){
//            return new JsonResult(1,"查无此人",null);
//        }
//        return new JsonResult(0,"查询成功",teachers.get(0));
//    }

//    @Override
//    public JsonResult updateTeacherMessage(Teacher teacher) {
//        int rows = teacherMapper.updateTeacherMessage(teacher);
//        if (rows<=0){
//            throw new RuntimeException("更新失败");
//        }
//        List<Teacher> teachers = teacherMapper.selectById(teacher.getId());
//        return new JsonResult(0,"更新成功",teachers.get(0));
//    }

//    @Override
//    public PageInfo selectAllTeachers(int pageNum, int pageSize, String search) {
//        PageHelper.startPage(pageNum,pageSize,search);
//        List<User> users = teacherMapper.selectAllTeachers();
//        PageInfo pageInfo = new PageInfo(users);
//        return pageInfo;
//    }

//    @Override
//    public JsonResult setUserBanned(Long id) {
//        int rows = teacherMapper.updateIsBanned2One(id);
//        if (rows<=0){
//            return new JsonResult(1,"封禁失败",null);
//        }
//        Message message = new Message();
//        message.setContent("账户因违规已被封禁");
//        message.setStatusCode(3);
////        List<Message> messages = new ArrayList<>();
////        messages.add(message);
//        ListOperations<String,Object> opsForList = redisTemplate.opsForList();
//        opsForList.rightPush("teacher:banned:"+id,message);
//        return new JsonResult(0,"禁用成功",null);
//    }

//    @Override
//    public JsonResult setUserEnable(Long id) {
//        int rows = teacherMapper.updateIsBanned2Zero(id);
//        if (rows<=0){
//            return new JsonResult(1,"启用失败",null);
//        }
//        return new JsonResult(0,"启用成功",null);
//    }

//    @Override
//    public JsonResult teacherCount() {
//        Long count = teacherMapper.teacherCount();
//        return new JsonResult(0,"教师总数",count);
//    }

//    @Override
//    public JsonResult teacherOrdinaryCount() {
//        return new JsonResult(0,"普通教师数量",teacherMapper.teacherOrdinaryCount());
//    }

//    @Override
//    public JsonResult teacherVipCount() {
//        return new JsonResult(0,"会员教师数量",teacherMapper.teacherVipCount());
//    }

//    @Override
//    public JsonResult resetUserPassword(User user) {
//        List<Teacher> teachers = teacherMapper.selectByUsernameAndPhone(user.getUsername(),user.getPhone());
//        if (teachers.size()<=0){
//            return new JsonResult(3,"教师表中没有查到相关人员",null);
//        }
//        userMapper.updatePasswordById(teachers.get(0).getId(),user.getPassword());
//        return new JsonResult(0,"密码修改成功",null);
//    }


}
